package com.shequan.activity.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ailk.dazzle.util.data.JSONUtils;
import com.shequan.activity.service.ActivityService;
import com.shequan.common.bean.ResultDataStruct;
import com.shequan.common.bean.ViewTextConstans;
import com.shequan.shequan.bean.bo.HotsActivityBean;
import com.shequan.shequan.bean.bo.SqActive;

/**
 * 
 * <P>
 * Copyright 2012 shequaner.
 * 
 * All Rights Reserved.
 * 
 * @author mazg
 * @version 1.0, 2012-4-15
 * @see com.shequan.activity.controller.ActivityController
 * @since 1.0
 */
@Controller
@RequestMapping("/activity")
public class ActivityController {

	private static final Logger log = Logger.getLogger(ActivityMemberController.class);
	private ActivityService activityService;

	@RequestMapping(value = "/all")
	public ModelAndView getAllActivity(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("---in postActivyMember---");

		ResultDataStruct<SqActive> rds = null;
		try {
			Integer shequanId = Integer.parseInt(request.getParameter("shequanId"));
			System.out.println(shequanId);
			if (rds.isBusiSuccess()) {
				request.setAttribute("sqActive", rds.getData());
			}
		} catch (Exception e) {
			if (rds == null) {
				rds = new ResultDataStruct<SqActive>();
			}
			log.error(e);
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
		}
		return new ModelAndView("/pages/shequan/shequan.jsp");
	}

	@RequestMapping(value = "/hotsAct")
	public void getHotsAct(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("---in getHotsAct---");
		ResultDataStruct<List<HotsActivityBean>> rds = new ResultDataStruct<List<HotsActivityBean>>();
		try {
			List<HotsActivityBean> hotsActList = activityService.queryAllHotsActList();
			rds.setData(hotsActList);
			rds.setBusiSuccess(true);
			rds.setSuccess(true);
		} catch (Exception e) {
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
			log.error(e);
		}
		String jsonData = JSONUtils.bean2JsonString(rds);
		log.debug(jsonData);
		response.getWriter().print(jsonData);
	}

	/**
	 * @param activityService
	 *            the activityService to set
	 */
	public void setActivityService(ActivityService activityService) {
		this.activityService = activityService;
	}

}
